package com.loveprogrammer.eternity.model.map;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.Hero;
import com.loveprogrammer.eternity.model.Monster;
import com.loveprogrammer.eternity.model.game.HeroWrapper;
import com.loveprogrammer.eternity.utils.BeanCopyUtils;
import com.loveprogrammer.eternity.utils.RandomBalance;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * @description:
 * @author: eric
 * @date: 2022-08-03 16:42
 **/
public class DefaultFindMonsters extends AbstractFindMonsters{

    @Override
    public List<Monster> findMonsters(HeroWrapper heroWrapper, Map map) throws Exception {
        List<Monster> result = new ArrayList<>();
        // 根据
        List<MonsterInMap> monsters = map.getMonsters();

        String[] teamSize = map.getTeamSize().split("-");
        int min = Integer.parseInt(teamSize[0]);
        int max = Integer.parseInt(teamSize[1]);

        int num;
        if(min == max){
            num = max;
        }else {
            num = min + new Random().nextInt(max - min);
        }
        for (int i = 0; i < num; i++) {
            Monster monster = RandomBalance.getMonsters(monsters);
            result.add(monster);
        }
        return BeanCopyUtils.deepCopy(result);
    }
}
